<template>
  <div class="login_container">
    <el-row>
      <el-col :span="12" :xs="0">.</el-col>
      <!-- xs 是当屏幕的宽度小于768px时，元素占的屏幕宽度的份数 -->
      <el-col :span="12" :xs="24">
        <el-form class="login_form">
          <!-- <h1>hello</h1> -->
          <h2>同软科技</h2>

          <el-form-item>
            <el-input v-model="form.username"></el-input>
          </el-form-item>

          <el-form-item>
            <el-input
              :show-password="true"
              type="password"
              v-model="form.password"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button class="login_btn" type="primary" @click="handleLogin"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
import { getMenu } from '../../api'
export default {
  data () {
    return {
      form: {
        username: 'admin',
        password: 'admin'
      },
      rules: {
        username: [
          { required: true, trigger: 'blur', message: '请输入用户名' }
        ],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      }
    }
  },
  methods: {
    handleLogin () {
      getMenu(this.form).then((res) => {
        // console.log(res)
        if (res.code === 20000) {
          Cookie.set('token', res.data.token)
          this.$message.success('登录成功')
          this.$router.push('/home')
        } else {
          this.$message({
            message: '账号密码错误，账号密码都是：admin',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login_container {
  width: 100%;
  height: 100vh;
  background: url("./background.jpg") no-repeat;
  background-size: cover;

  .login_form {
    position: relative;
    width: 80%;
    top: 30vh;
    background: url("./login_form.png") no-repeat;
    background-size: cover;
    padding: 40px;
  }

  h1 {
    font-size: 40px;
    color: #fff;
  }

  h2 {
    font-size: 20px;
    color: #fff;
    margin: 20px 0;
  }

  .login_btn {
    width: 100%;
  }
}
</style>
